package com.example.nfcproducttracing;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;


public class StartFragment extends Fragment
{
	AlphaAnimation fadeIn = new AlphaAnimation(0.0f , 1.0f );
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.start, container, false);
    }
    
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState)
    {
    	super.onViewCreated(view, savedInstanceState);
    	
    	final Button scanBanner = (Button) getView().findViewById(R.id.ScanBanner);

    	fadeIn.setDuration(2500);
    	
    	fadeIn.setAnimationListener(new AnimationListener() {
    	    private int cycle = 0;
    	    
			@Override
    	    public void onAnimationRepeat(Animation animation) {
    	        cycle = (cycle + 1) % 6;
    	        if (cycle == 0) {
    	            scanBanner.setBackgroundResource(R.drawable.rounded_purple);
    	        } else if (cycle == 2) {
    	            scanBanner.setBackgroundResource(R.drawable.rounded_blue);
    	        } else if (cycle == 4) {
    	            scanBanner.setBackgroundResource(R.drawable.rounded_green);
    	        }
    	    }
			@Override
			public void onAnimationStart(Animation animation) {}
			@Override
			public void onAnimationEnd(Animation animation) {}
    	});
    	scanBanner.startAnimation(fadeIn);

    	fadeIn.setRepeatCount(Animation.INFINITE);
    	fadeIn.setRepeatMode(Animation.REVERSE);
    }
}